package com.yidu.hbatsft.action;

import com.yidu.hbatsft.domain.AtsEmpAthlete;
import com.yidu.hbatsft.domain.AtsEmpAthleteResults;
import com.yidu.hbatsft.service.AtsEmpResultsService;
import com.yidu.privilege.vo.UserVo;
import com.yidu.utils.Message;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import javax.servlet.http.HttpSession;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Controller
@RequestMapping("/AtsEmpAthleteResults")
public class AtsEmpAthleteResultsController {

    @Resource
    private AtsEmpResultsService service;
    /**
     * 查询全部
     * @param matchName 比赛名称
     * @param pageNum
     * @param pageSize
     * @return
     */
    @RequestMapping("findAll")
    @ResponseBody
    public Map<String,Object> findAll(String matchName, @RequestParam("page") Integer pageNum, @RequestParam("limit") Integer pageSize){
        //根据教练ID查询运动员
        Map<String,Object> map = new HashMap<String,Object>();

        List<AtsEmpAthleteResults> ata =  service.findAll(matchName,pageNum,pageSize);
        int cout = service.cout();
        for (AtsEmpAthleteResults atsEmpAthleteResults : ata) {
            System.err.println(atsEmpAthleteResults.getAthleteName()+"================="+cout);
        }

        map.put("code",0);
        map.put("msg","");
        map.put("count",cout);
        map.put("data",ata);

        return map;
    }

    @RequestMapping("loadingAthleteName")
    @ResponseBody
    public List<AtsEmpAthlete> loadingAthleteName(){
        List<AtsEmpAthlete> list =service.loadingAthleteName();
        return list;
    }

    @RequestMapping("findByid")
    @ResponseBody
    public AtsEmpAthleteResults findByid(Integer id){
        AtsEmpAthleteResults ats = service.findByid(id);
        System.out.println(id);
        return  ats;
    }

    @RequestMapping("insertOrupDate")
    @ResponseBody
    public Message insertOrupDate(AtsEmpAthleteResults ats){
        Message msg = new Message();

        System.out.println(ats.getAthleteName()+":e"+ats.getAthleteId());
        int cout = service.insertOrupDate(ats);
        if(cout >0){
            msg.setNum(1);
        }else{
            msg.setNum(0);
        }
        return msg;
    }

    @RequestMapping("deletematchDate")
    @ResponseBody
    public Message deletematchDate(Integer id){
        Message msg = new Message();
        int cout = service.deleteByid(id);
        if(cout>0){
            msg.setMsg("操作成功");
        }else{
            msg.setMsg("操作失败");
        }
        return msg;
    }

    @RequestMapping("deletematchDates")
    @ResponseBody
    public Message deletematchDates(String ids){
        Message msg = new Message();
        String id [] = ids.split(",");
        int cout =0;
        for (int i=0;i<id.length;i++){
            Integer e = Integer.valueOf(id[i]);
            cout = service.deleteByid(e);
        }
        if(cout>0){
            msg.setMsg("操作成功");
        }else{
            msg.setMsg("操作失败");
        }
        return  msg;
    }
}
